package HuaWeiOd.online;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 扑克牌大小
 * @author caihe
 * @date 2023/4/14 20:37
 */
public class B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Set<Integer> sets = new HashSet<>();
        int[] arr = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        // 统计牌出现的次数
        Map<Integer, Integer> map = new TreeMap<>();
        for (int num : arr) {
            Integer count = map.getOrDefault(num, 0);
            map.put(num, count + 1);
        }
        Map<Integer, Map<Integer, List<Integer>>> map1 = new TreeMap<>((o1, o2) -> o2-o1);

        for (Integer key : map.keySet()) {
            Integer count = map.get(key);
            int[] narr = new int[count];
            Arrays.fill(narr, key);


            Map<Integer, List<Integer>> map2 = map1.getOrDefault(count, new TreeMap<>((o1, o2) -> o2 - o1));

            List<Integer> collect = Arrays.stream(narr).boxed().collect(Collectors.toList());
            map2.put(key, collect);

            map1.put(count, map2);
        }

        Queue<Integer> queue=new PriorityQueue<>((o1, o2) -> o2-o1);

        for (Integer key : map1.keySet()) {
            Map<Integer, List<Integer>> integerListMap = map1.get(key);
            if (key >= 4 || key == 2) {
                for (List<Integer> value : integerListMap.values()) {
                    for (Integer integer : value) {
                        if (key == 2 && sets.contains(integer)) {
                            continue;
                        }
                        System.out.print(integer + " ");


                    }
                }
            } else if (key == 1) {
                for (List<Integer> value : integerListMap.values()) {
                    for (Integer integer : value) {
                        queue.add(integer);
                    }
                }
            } else if (key == 3) {

                Iterator<Integer> iterator1 = integerListMap.keySet().iterator();
                for (List<Integer> value : integerListMap.values()) {


//                while (iterator1.hasNext()) {
//                    Integer key1 = iterator1.next();

//                    List<Integer> value = integerListMap.get(key1);
                    if (sets.contains(value.get(0))){
                        continue;
                    }

                    for (Integer integer : value) {
                        System.out.print(integer + " ");
                    }
                    sets.add(value.get(0));
//                    integerListMap.remove(key1);


                    // 取出所有三张和对子

                    boolean flag = true;
                    for (int i = 3; i >= 2 && flag; i--) {
                        Map<Integer, List<Integer>> integerListMap1 = map1.get(i);
                        if (integerListMap1 != null && integerListMap1.keySet().size() != 0) {
                            if (i == 3) {
                                // 取出两个 设置一张到里面去
                                Iterator<Integer> iterator = integerListMap1.keySet().iterator();
                                while(iterator.hasNext()) {
                                    Integer next = iterator.next();
                                    if (sets.contains(next)){
                                        continue;
                                    }
                                    List<Integer> integers = integerListMap1.get(next);
                                    for (int j = 0; j < 2; j++) {
                                        System.out.print(integers.get(j) + " ");
                                    }
//                                    integerListMap1.remove(next);
                                    // 设置一张
//                                    Map<Integer, List<Integer>> integerListMap2 = map1.getOrDefault(1, new TreeMap<>((o1, o2) -> o2 - o1));
//                                    integerListMap2.put(next, Arrays.asList(next));
                                    sets.add(next);
//                                    map1.put(1, integerListMap2);
//                                    map1.put(i, integerListMap1);
                                    queue.add(next);
                                    flag = false;
                                    break ;
                                }

                            } else {
                                Iterator<Integer> iterator = integerListMap1.keySet().iterator();
                                while(iterator.hasNext()) {
                                    Integer next = iterator.next();
                                    if (sets.contains(next)){
                                        continue;
                                    }
                                    List<Integer> integers = integerListMap1.get(next);
                                    for (Integer integer : integers) {
                                        System.out.print(integer + " ");
                                    }
                                    sets.add(next);
//                                    integerListMap1.remove(next);
//                                    map1.put(i, integerListMap1);
                                    flag = false;
                                    break;
                                }
                            }
                        }
                    }

                }

            }
        }

        for (Integer integer : queue) {
            System.out.print(integer + " ");
        }



        System.out.println();

    }
}
